<?php 

include 'FileAction.class.php';
	
class SocketTool{
    private $host = '地址';
    private $port='端口';
	private $socket='';
    //建立通讯接口
    public function funSocket($msg){
        set_time_limit(0);
        //创建一个socket
        $this->socket=socket_create(AF_INET,SOCK_STREAM,SOL_TCP)or die("cannot create socket\n");
        //进行接口连接
        $conn=socket_connect($this->socket,$this->host,$this->port) or die("cannot connect server\n");
        if($conn){echo "client connect ok!";}
        //向接口写数据
        $write=socket_write($this->socket,$msg) or die("cannot write data\n");
        //关闭接口
        socket_close($this->socket);
    }
    //下面的方法暂时不使用
    public function openSocket(){
        set_time_limit(0);
        $socket=socket_create(AF_INET,SOCK_STREAM,SOL_TCP)or die("cannot create socket\n");
        $conn=socket_connect($socket,"192.168.100.236","5432") or die("cannot connect server\n");
        if($conn){echo "client connect ok!";}
		return $socket;
    }
    public function writeSocket($socketData,$msg){
		
        $write=socket_write($socketData,$msg) or die("cannot write data\n");
    }
	
    public function closeSocket($socketData){
        socket_close($socketData);
    }
}
?>